<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        input{
            width: 200px;
            height: 100px;
            background-color: yellow;
            position: relative;
            top: 200px;
            left: 500px;
        }


    </style>

</head>
<body>
<input type="button" value="返回日期是所在年份的第几天"
       onclick="DayOfYear(prompt('请输入日期（格式为20000102）'))"/>

<script>
    function DayOfYear(d) {
        var months1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var months2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var isLeapYear = false;
        var order = 0;
        var len = Number(d.substr(4, 2));

        if (Number(d.substring(0, 4)) % 100 == 0 && Number(d.substring(0, 4)) % 400 == 0) {
            isLeapYear = true;
            document.write("你好");
        }
        if (Number(d.substring(0, 4)) % 100 != 0 && Number(d.substring(0, 4)) % 4 == 0) {
            isLeapYear = true;
            document.write("你好");
        } else {
            isLeapYear = false;
        }
        if (isLeapYear == true) {
            for (let i = 0; i < len - 1; i++) {
                order += months2[i];
            }
        }
        if (isLeapYear == false) {
            for (let i = 0; i < len - 1; i++) {
                order += months1[i];
            }
        }
        alert("此日期是" + d.substring(0, 4) + "年的第" + (order + Number(d.substring(6, 8))) + "天");
    }
</script>

</body>
</html>


<!--3.设计一个函数DayOfYear(d)，它接收一个日期参数d，返回一个该日期是所在年份的第几天，
如DayOfYear(2000,2,8)的返回值是39.
提示：
①定义一个数组var months= [31,28,31,30,31,30,31,31,30,31,30,31]记录每个月多少天
②定义一个辅助函数IsLeapYear(year)判定某个年份是否闰年，以确定2月份的天数是28还是29。!-->